package cre.tomcat7.ch00.core;

import org.apache.catalina.*;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.juli.logging.Log;

import javax.management.ObjectName;
import javax.naming.directory.DirContext;
import javax.servlet.ServletException;
import java.beans.PropertyChangeListener;
import java.io.IOException;

/**
 * @Author penglai
 * @Date 2017/3/21.
 */
public class SimpleContainer implements Container {
    /**
     * Return descriptive information about this Container implementation and
     * the corresponding version number, in the format
     * <code>&lt;description&gt;/&lt;version&gt;</code>.
     */
    @Override
    public String getInfo() {
        return null;
    }

    /**
     * Return the Loader with which this Container is associated.  If there is
     * no associated Loader, return the Loader associated with our parent
     * Container (if any); otherwise, return <code>null</code>.
     */
    @Override
    public Loader getLoader() {
        return null;
    }

    /**
     * Set the Loader with which this Container is associated.
     *
     * @param loader The newly associated loader
     */
    @Override
    public void setLoader(Loader loader) {

    }

    /**
     * Return the Logger with which this Container is associated.  If there is
     * no associated Logger, return the Logger associated with our parent
     * Container (if any); otherwise return <code>null</code>.
     */
    @Override
    public Log getLogger() {
        return null;
    }

    /**
     * Return the Manager with which this Container is associated.  If there is
     * no associated Manager, return the Manager associated with our parent
     * Container (if any); otherwise return <code>null</code>.
     */
    @Override
    public Manager getManager() {
        return null;
    }

    /**
     * Set the Manager with which this Container is associated.
     *
     * @param manager The newly associated Manager
     */
    @Override
    public void setManager(Manager manager) {

    }

    /**
     * Return an object which may be utilized for mapping to this component.
     */
    @Override
    public Object getMappingObject() {
        return null;
    }

    /**
     * Return the JMX name associated with this container.
     */
    @Override
    public ObjectName getObjectName() {
        return null;
    }

    /**
     * Return the Pipeline object that manages the Valves associated with
     * this Container.
     */
    @Override
    public Pipeline getPipeline() {
        return null;
    }

    /**
     * Return the Cluster with which this Container is associated.  If there is
     * no associated Cluster, return the Cluster associated with our parent
     * Container (if any); otherwise return <code>null</code>.
     */
    @Override
    public Cluster getCluster() {
        return null;
    }

    /**
     * Set the Cluster with which this Container is associated.
     *
     * @param cluster the Cluster with which this Container is associated.
     */
    @Override
    public void setCluster(Cluster cluster) {

    }

    /**
     * Get the delay between the invocation of the backgroundProcess method on
     * this container and its children. Child containers will not be invoked
     * if their delay value is not negative (which would mean they are using
     * their own thread). Setting this to a positive value will cause
     * a thread to be spawn. After waiting the specified amount of time,
     * the thread will invoke the executePeriodic method on this container
     * and all its children.
     */
    @Override
    public int getBackgroundProcessorDelay() {
        return 0;
    }

    /**
     * Set the delay between the invocation of the execute method on this
     * container and its children.
     *
     * @param delay The delay in seconds between the invocation of
     *              backgroundProcess methods
     */
    @Override
    public void setBackgroundProcessorDelay(int delay) {

    }

    /**
     * Return a name string (suitable for use by humans) that describes this
     * Container.  Within the set of child containers belonging to a particular
     * parent, Container names must be unique.
     */
    @Override
    public String getName() {
        return null;
    }

    /**
     * Set a name string (suitable for use by humans) that describes this
     * Container.  Within the set of child containers belonging to a particular
     * parent, Container names must be unique.
     *
     * @param name New name of this container
     * @throws IllegalStateException if this Container has already been
     *                               added to the children of a parent Container (after which the name
     *                               may not be changed)
     */
    @Override
    public void setName(String name) {

    }

    /**
     * Return the Container for which this Container is a child, if there is
     * one.  If there is no defined parent, return <code>null</code>.
     */
    @Override
    public Container getParent() {
        return null;
    }

    /**
     * Set the parent Container to which this Container is being added as a
     * child.  This Container may refuse to become attached to the specified
     * Container by throwing an exception.
     *
     * @param container Container to which this Container is being added
     *                  as a child
     * @throws IllegalArgumentException if this Container refuses to become
     *                                  attached to the specified Container
     */
    @Override
    public void setParent(Container container) {

    }

    /**
     * Return the parent class loader for this component. If not set, return
     * {@link #getParent()} {@link #getParentClassLoader()}. If no parent has
     * been set, return the system class loader.
     */
    @Override
    public ClassLoader getParentClassLoader() {
        return null;
    }

    /**
     * Set the parent class loader for this component. For {@link Context}s
     * this call is meaningful only <strong>before</strong> a Loader has
     * been configured, and the specified value (if non-null) should be
     * passed as an argument to the class loader constructor.
     *
     * @param parent The new parent class loader
     */
    @Override
    public void setParentClassLoader(ClassLoader parent) {

    }

    /**
     * Return the Realm with which this Container is associated.  If there is
     * no associated Realm, return the Realm associated with our parent
     * Container (if any); otherwise return <code>null</code>.
     */
    @Override
    public Realm getRealm() {
        return null;
    }

    /**
     * Set the Realm with which this Container is associated.
     *
     * @param realm The newly associated Realm
     */
    @Override
    public void setRealm(Realm realm) {

    }

    /**
     * Return the Resources with which this Container is associated.  If there
     * is no associated Resources object, return the Resources associated with
     * our parent Container (if any); otherwise return <code>null</code>.
     */
    @Override
    public DirContext getResources() {
        return null;
    }

    /**
     * Set the Resources object with which this Container is associated.
     *
     * @param resources The newly associated Resources
     */
    @Override
    public void setResources(DirContext resources) {

    }

    /**
     * Execute a periodic task, such as reloading, etc. This method will be
     * invoked inside the classloading context of this container. Unexpected
     * throwables will be caught and logged.
     */
    @Override
    public void backgroundProcess() {

    }

    /**
     * Add a new child Container to those associated with this Container,
     * if supported.  Prior to adding this Container to the set of children,
     * the child's <code>setParent()</code> method must be called, with this
     * Container as an argument.  This method may thrown an
     * <code>IllegalArgumentException</code> if this Container chooses not
     * to be attached to the specified Container, in which case it is not added
     *
     * @param child New child Container to be added
     * @throws IllegalArgumentException if this exception is thrown by
     *                                  the <code>setParent()</code> method of the child Container
     * @throws IllegalArgumentException if the new child does not have
     *                                  a name unique from that of existing children of this Container
     * @throws IllegalStateException    if this Container does not support
     *                                  child Containers
     */
    @Override
    public void addChild(Container child) {

    }

    /**
     * Add a container event listener to this component.
     *
     * @param listener The listener to add
     */
    @Override
    public void addContainerListener(ContainerListener listener) {

    }

    /**
     * Add a property change listener to this component.
     *
     * @param listener The listener to add
     */
    @Override
    public void addPropertyChangeListener(PropertyChangeListener listener) {

    }

    /**
     * Return the child Container, associated with this Container, with
     * the specified name (if any); otherwise, return <code>null</code>
     *
     * @param name Name of the child Container to be retrieved
     */
    @Override
    public Container findChild(String name) {
        return null;
    }

    /**
     * Return the set of children Containers associated with this Container.
     * If this Container has no children, a zero-length array is returned.
     */
    @Override
    public Container[] findChildren() {
        return new Container[0];
    }

    /**
     * Return the set of container listeners associated with this Container.
     * If this Container has no registered container listeners, a zero-length
     * array is returned.
     */
    @Override
    public ContainerListener[] findContainerListeners() {
        return new ContainerListener[0];
    }

    /**
     * Process the specified Request, and generate the corresponding Response,
     * according to the design of this particular Container.
     *
     * @param request  Request to be processed
     * @param response Response to be produced
     * @throws IOException      if an input/output error occurred while
     *                          processing
     * @throws ServletException if a ServletException was thrown
     *                          while processing this request
     * @deprecated Unused. Will be removed in Tomcat 8.0.x.
     */
    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException {
        System.out.println("in simpleContainer invoke");
    }

    /**
     * Remove an existing child Container from association with this parent
     * Container.
     *
     * @param child Existing child Container to be removed
     */
    @Override
    public void removeChild(Container child) {

    }

    /**
     * Remove a container event listener from this component.
     *
     * @param listener The listener to remove
     */
    @Override
    public void removeContainerListener(ContainerListener listener) {

    }

    /**
     * Remove a property change listener from this component.
     *
     * @param listener The listener to remove
     */
    @Override
    public void removePropertyChangeListener(PropertyChangeListener listener) {

    }

    /**
     * Notify all container event listeners that a particular event has
     * occurred for this Container.  The default implementation performs
     * this notification synchronously using the calling thread.
     *
     * @param type Event type
     * @param data Event data
     */
    @Override
    public void fireContainerEvent(String type, Object data) {

    }

    /**
     * Log a request/response that was destined for this container but has been
     * handled earlier in the processing chain so that the request/response
     * still appears in the correct access logs.
     *
     * @param request    Request (associated with the response) to log
     * @param response   Response (associated with the request) to log
     * @param time       Time taken to process the request/response in
     *                   milliseconds (use 0 if not known)
     * @param useDefault Flag that indicates that the request/response should
     */
    @Override
    public void logAccess(Request request, Response response, long time, boolean useDefault) {

    }

    /**
     * Identify the AccessLog to use to log a request/response that was destined
     * for this container but was handled earlier in the processing chain so
     * that the request/response still appears in the correct access logs.
     */
    @Override
    public AccessLog getAccessLog() {
        return null;
    }

    /**
     * Returns the number of threads available for starting and stopping any
     * children associated with this container. This allows start/stop calls to
     * children to be processed in parallel.
     */
    @Override
    public int getStartStopThreads() {
        return 0;
    }

    /**
     * Sets the number of threads available for starting and stopping any
     * children associated with this container. This allows start/stop calls to
     * children to be processed in parallel.
     *
     * @param startStopThreads The new number of threads to be used
     */
    @Override
    public void setStartStopThreads(int startStopThreads) {

    }

    /**
     * Add a LifecycleEvent listener to this component.
     *
     * @param listener The listener to add
     */
    @Override
    public void addLifecycleListener(LifecycleListener listener) {

    }

    /**
     * Get the life cycle listeners associated with this life cycle. If this
     * component has no listeners registered, a zero-length array is returned.
     */
    @Override
    public LifecycleListener[] findLifecycleListeners() {
        return new LifecycleListener[0];
    }

    /**
     * Remove a LifecycleEvent listener from this component.
     *
     * @param listener The listener to remove
     */
    @Override
    public void removeLifecycleListener(LifecycleListener listener) {

    }

    /**
     * Prepare the component for starting. This method should perform any
     * initialization required post object creation. The following
     * {@link LifecycleEvent}s will be fired in the following order:
     * <ol>
     * <li>INIT_EVENT: On the successful completion of component
     * initialization.</li>
     * </ol>
     *
     * @throws LifecycleException if this component detects a fatal error
     *                            that prevents this component from being used
     */
    @Override
    public void init() throws LifecycleException {

    }

    /**
     * Prepare for the beginning of active use of the public methods other than
     * property getters/setters and life cycle methods of this component. This
     * method should be called before any of the public methods other than
     * property getters/setters and life cycle methods of this component are
     * utilized. The following {@link LifecycleEvent}s will be fired in the
     * following order:
     * <ol>
     * <li>BEFORE_START_EVENT: At the beginning of the method. It is as this
     * point the state transitions to
     * {@link LifecycleState#STARTING_PREP}.</li>
     * <li>START_EVENT: During the method once it is safe to call start() for
     * any child components. It is at this point that the
     * state transitions to {@link LifecycleState#STARTING}
     * and that the public methods other than property
     * getters/setters and life cycle methods may be
     * used.</li>
     * <li>AFTER_START_EVENT: At the end of the method, immediately before it
     * returns. It is at this point that the state
     * transitions to {@link LifecycleState#STARTED}.
     * </li>
     * </ol>
     *
     * @throws LifecycleException if this component detects a fatal error
     *                            that prevents this component from being used
     */
    @Override
    public void start() throws LifecycleException {

    }

    /**
     * Gracefully terminate the active use of the public methods other than
     * property getters/setters and life cycle methods of this component. Once
     * the STOP_EVENT is fired, the public methods other than property
     * getters/setters and life cycle methods should not be used. The following
     * {@link LifecycleEvent}s will be fired in the following order:
     * <ol>
     * <li>BEFORE_STOP_EVENT: At the beginning of the method. It is at this
     * point that the state transitions to
     * {@link LifecycleState#STOPPING_PREP}.</li>
     * <li>STOP_EVENT: During the method once it is safe to call stop() for
     * any child components. It is at this point that the
     * state transitions to {@link LifecycleState#STOPPING}
     * and that the public methods other than property
     * getters/setters and life cycle methods may no longer be
     * used.</li>
     * <li>AFTER_STOP_EVENT: At the end of the method, immediately before it
     * returns. It is at this point that the state
     * transitions to {@link LifecycleState#STOPPED}.
     * </li>
     * </ol>
     * <p>
     * Note that if transitioning from {@link LifecycleState#FAILED} then the
     * three events above will be fired but the component will transition
     * directly from {@link LifecycleState#FAILED} to
     * {@link LifecycleState#STOPPING}, bypassing
     * {@link LifecycleState#STOPPING_PREP}
     *
     * @throws LifecycleException if this component detects a fatal error
     *                            that needs to be reported
     */
    @Override
    public void stop() throws LifecycleException {

    }

    /**
     * Prepare to discard the object. The following {@link LifecycleEvent}s will
     * be fired in the following order:
     * <ol>
     * <li>DESTROY_EVENT: On the successful completion of component
     * destruction.</li>
     * </ol>
     *
     * @throws LifecycleException if this component detects a fatal error
     *                            that prevents this component from being used
     */
    @Override
    public void destroy() throws LifecycleException {

    }

    /**
     * Obtain the current state of the source component.
     *
     * @return The current state of the source component.
     */
    @Override
    public LifecycleState getState() {
        return null;
    }

    /**
     * Obtain a textual representation of the current component state. Useful
     * for JMX.
     */
    @Override
    public String getStateName() {
        return null;
    }
}
